package com.wpml.orm;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class QueryListHandler<T> implements OrmHandler<List<T>>{

    Class<T> clazz;

    public QueryListHandler(Class<T> clazz) {
        this.clazz = clazz;
    }

    @Override
    public List<T> handler(ResultSet rs) throws Exception {
        List<T> list = new ArrayList<>();

        if (rs == null) {
            return list;
        }

        int[] ints = JdbcUtils.column2Property(rs, clazz.getDeclaredFields());

        while (rs.next()) {
            list.add(JdbcUtils.result2PO(rs, ints, clazz));
        }
        return list;
    }
}
